package com.gulimall.search.controller;

import com.gulimall.common.exception.BizCondeEnume;
import com.gulimall.common.to.es.SkuEsModels;
import com.gulimall.common.utils.R;
import com.gulimall.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 * @Author: Zk
 * @Date: 2020/12/1 8:25
 */
@Slf4j
@RequestMapping("/search/save")
@RestController
public class ElasticSaveControllers {
    @Autowired
    ProductSaveService productSaveService;
    //上架商品
    @PostMapping("product")
    public R productStatusUp(@RequestBody List<SkuEsModels> skuEsModers){
        boolean b;
        try {
             b = productSaveService.productStatusUp(skuEsModers);
        }catch (Exception e){
            log.error("ElasticSaveControllers商品上架错误：{}",e);
            return R.error(BizCondeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizCondeEnume.PRODUCT_UP_EXCEPTION.getMsg());
        }
        if (!b){
            return R.ok();
        }else {
            return R.error(BizCondeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizCondeEnume.PRODUCT_UP_EXCEPTION.getMsg());
        }
    }
}
